-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Glibc module: detect location of glibc header files #282
Glibc module: detect location of glibc header files #282
Conversation
set(GLIBC_INCLUDE_PATH "/usr/include") | ||
set(arch_dir "x86_64-linux-gnu") | ||
if (EXISTS "${GLIBC_INCLUDE_PATH}/${arch_dir}/sys") | ||
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}/${arch_dir}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use two spaces for indentation, for spaces for line continuations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gribozavr: How about adding an uncrustify config to the project that has your code formatting so that we run it as a git-hook before making pull requests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a bigger discussion that should be held on swift-dev@swift.org. Feel free to start it, but I don't think you should block your patch on that.
I ran the tests on Ubuntu 14.04 and it looks good. Please make the formatting and style changes that I mentioned above, and I'll merge. |
set(outputs) | ||
# Set correct paths to glibc headers | ||
set(GLIBC_INCLUDE_PATH "/usr/include") | ||
set(arch_dir "x86_64-linux-gnu") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using CMAKE_LIBRARY_ARCHITECTURE
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, as a side note: At some point it there will probably be a better way to get this path: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=796545
Can confirm that this makes the build work on Arch as well. |
I can confirm that this makes the build work on Fedora 23 as well. |
1487d75
to
041c031
Compare
Updated the commit:
|
Nice work. A question though: What happened to the creation of the output directory now? It seems it's gone. Is it created implicitly somehow, or have we all had the directory already created when we tested this? Also, and this is just a suggestion, but couldn't the set(sources
Glibc.swift
)
set(output_dir "${SWIFTLIB_DIR}/glibc")
file(MAKE_DIRECTORY "${output_dir}")
# Set correct paths to glibc headers
set(GLIBC_INCLUDE_PATH "/usr/include")
if(CMAKE_LIBRARY_ARCHITECTURE)
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}/${CMAKE_LIBRARY_ARCHITECTURE}")
else()
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}")
endif()
if (NOT EXISTS "${GLIBC_ARCH_INCLUDE_PATH}/sys")
message(FATAL_ERROR "Glibc headers were not found.")
endif()
configure_file(module.map.in "${output_dir}/module.map" @ONLY)
swift_install_in_component(stdlib
FILES "${output_dir}/module.map"
DESTINATION "lib/swift/glibc")
add_swift_library(swiftGlibc IS_SDK_OVERLAY
${sources}
FILE_DEPENDS "${output_dir}/module.map" "${SWIFTLIB_DIR}/glibc"
INSTALL_IN_COMPONENT stdlib-experimental) What I did was:
I'll let someone from the Swift project comment on what they think of that. |
I also realized now that with the custom command target gone, I get
with CMake 3.4.0. The custom command DEPENDS it speaks of is that added by Could always do |
It's verified with a clean build that the directory is created, so that works fine. I didn't want to rewrite too much of the file, because I'm new to CMake, but I agree that it can be simplified. And indeed, it might be best to have a look at that another time. Regarding the warning, I didn't catch that, but just adding the custom command target back in seems pointless to me, since it's not really doing anything anymore. I would expect that it's possible to depend on a generated configuration file, but I can have another look at it tomorrow. In the meantime, if someone with more CMake experience has an easy solution, let me know. |
Alright. Good that the mkdir is not needed. Yes, any possible simplifications can be another PR. Just wanted to throw it out there :) I agree it's a little silly to have a "dummy" custom command. And the warning will only appear on CMake 3.4.0+, which are very new versions. So let's postpone that as well. I get truckloads of such policy warnings about other things anyway. To me this can go in as is. |
This should be fixed by swiftlang#282
👍 Was considering doing similar things. Tested it on Fedora 23, works well. |
In the Glibc module map all sys/... header files had the following paths: /usr/include/x86_64-linux-gnu/sys/..., but some distros install them in /usr/include/sys/...
041c031
to
3d91979
Compare
Final update (hopefully). I'm becoming a CMake expert now, so I dared to rewrite a bit more ;)
This seems to be the only solution to prevent the CMP0058 policy warning. I think normally you don't directly depend on generated configuration, but have an automatic dependency. For example with config.h. In this case we want to depend on module.map explicitly and it seems we need a custom command target for that. There are other solutions, like generating a script for doing the substitutions, or generating a CMake file that is used during build, but I didn't want to move away too far from the working solution. If required, we can improve later. Only drawback I see is the extra file we create, furthermore this solution works fine:
|
Thanks for this. I'd like to test this fix on Scientific Linux 7.1, but I'm having trouble applying the patch. I replaced stdlib/public/Glibc/CMakeLists.txt with the version from this commit, and likewise removed stdlib/public/Glibc/module.map and added the stdlib/public/Glibc/module.map.in from this commit. But after doing so, the build doesn't know how to create stdlib/public/Glibc/module.map:
How should this fix be applied? Sorry for such a simple question - I'm fairly new to cmake and don't know ninja at all. |
The changed build configuration should be detected. Did you try to run the build-script, or are you running cmake manually? |
I forgot to switch to the appropriate branch. Once I did that, I was able to build successfully on Scientific Linux 7.1 |
Ok 👍 |
I tested on Ubuntu 14.04 and it works. |
Glibc module: detect location of glibc header files
…s-tests test suite fixes to prep for enabling additional warnings
Add support for Swift 5.0 branch
…file [cxx-interop] Add `usr/include/module.modulemap` file
In the Glibc module map all sys/... header files had the following paths:
/usr/include/x86_64-linux-gnu/sys/..., but some distros install them in
/usr/include/sys/...
I tried using relative paths and make the compiler find them, but apparently it doesn't work that way. Since the paths are already absolute I guess that's how it's supposed to be, so this seems the best solution to me. If someone has a better suggestion, please let me know. This is verified on Fedora 23 and Ubuntu 15.10.
I'm new to clang, CMake and GitHub, so feel free to point out anything that could be improved.